package com.beilang.base.core.dao;

import java.util.Map;

import com.beilang.base.pagination.PaginationHelper;

public abstract class PaginationBaseDAO extends BaseDAO{
	protected Map constructPaginationMap (PaginationHelper helper, Map map) {
        int start=helper.getStart();
        int end=helper.getEnd();
        int objectPerPage=helper.getObjectPerPage();
        int fullSize=helper.getTotalSize();
        if(end>fullSize){
        	end=fullSize;
        }
        if(start==end&&start!=0){
        	start=start-objectPerPage;
        	if(start<0)start=0;
        }
        if(start+objectPerPage>end){
        	objectPerPage=end-start;
        }
        helper.setStart(start);
        map.put(PaginationHelper.REC_PER_PAGE,objectPerPage);
        map.put(PaginationHelper.CURRENT_RANGE,end);
        map.put(PaginationHelper.SORT_FIELD, mapSortField(helper.getSortField()));
        map.put(PaginationHelper.SORT_DIR, helper.getSortDir());     
        return map;
    }
	
	protected abstract String mapSortField(String dataField);
    

}
